cqjs.component('carView', {
    template: `
    <div class="card-view">
        <div class="tool-bar" style="display: flex; justify-content: space-between; padding: 5px 0">
            <div>
                <el-button type="success" @click="$props.onCreate">创建</el-button>
                <el-dropdown split-button type="primary" :disabled="$props.selected.data == null" @click="$props.onEdit" @command="handleCommand">
                    编辑
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item command="delete" style="min-width:100px">删除</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </div>
        </div>
    </div>
    `,
    props: ['onSearch', 'onCreate', 'onEdit', 'data', 'meta', 'arch', 'selected'],
    data() {
        const xml = cqjs.utils.parseXML(this.$props.arch);
        const columns = [];
        xml.find('field').each(function () {
            const field = $(this);
            const name = field.attr('name');
            columns.push(name)
        });
        return {
            columns
        }
    },
    methods: {
        setCurrent(row) {
            this.$refs.singleTable.setCurrentRow(row);
        },
        handleCurrentChange(val, old) {
            this.selected.data = val;
            this.selected.index = this.data.indexOf(val);
        },
        handleCommand(cmd) {

        },
        formatterTableData(row, column, cellValue, index) {
            const options = this.$props.meta.fields[column.property].options
            if (options) {
                return options[cellValue]
            }
            return cellValue
        },
    }
});